package com.d3works.apps.account.service.payment.invoice.payment;

import com.d3works.apps.account.db.Invoice;
import com.d3works.apps.account.db.InvoicePayment;
import com.d3works.apps.account.db.InvoiceTerm;
import com.d3works.apps.account.db.MoveLine;
import com.d3works.apps.base.db.BankDetails;
import com.d3works.apps.base.db.Company;
import com.d3works.exception.D3worksException;
import com.google.inject.persist.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

public interface InvoicePaymentToolService {

  @Transactional(rollbackOn = {Exception.class})
  public void updateAmountPaid(Invoice invoice) throws D3worksException;

  void updateHasPendingPayments(Invoice invoice);

  public void updatePaymentProgress(Invoice invoice);

  /**
   * @param company company from the invoice
   * @param invoicePayment
   * @return list of bankdetails in the payment mode for the given company.
   */
  public List<BankDetails> findCompatibleBankDetails(
      Company company, InvoicePayment invoicePayment);

  List<InvoicePayment> assignAdvancePayment(Invoice invoice, Invoice advancePayment);

  /**
   * Method to get move lines from payment. The move lines are either credit or debit depending on
   * the value of getCreditLine
   *
   * @param payments
   * @param getCreditLine
   * @return
   */
  List<MoveLine> getMoveLinesFromPayments(List<InvoicePayment> payments, boolean getCreditLine);

  public void checkConditionBeforeSave(InvoicePayment invoicePayment) throws D3worksException;

  BigDecimal getPayableAmount(
      List<InvoiceTerm> invoiceTermList, LocalDate date, boolean manualChange);

  void computeFinancialDiscount(InvoicePayment invoicePayment);

  BigDecimal getMassPaymentAmount(List<Long> invoiceIdList, LocalDate date);

  boolean applyFinancialDiscount(InvoicePayment invoicePayment);

  void computeFromInvoiceTermPayments(InvoicePayment invoicePayment);
}
